package com.hadoopSpark.application.test;
/*
 * 显示应用的基本信息
 */
import org.apache.http.Header;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import com.aliyun.configuration.ConfigurationTool;
import com.certificate.tool.SetTrustStore;
import com.common.constant.Constant;

public class ShowAppBaseInfo {
	
	public static void main(String[] args) throws Exception {
		 
		 SSLConnectionSocketFactory sslsf = SetTrustStore.getSSLConnection();
		 
		 //httpclient链接
		 CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
		 
		 try {
			 HttpGet httpGet = null;
			if (! args[0].equals("")) {//说明用户，传入了参数， 这个是，查看集群的详细信息，如查看某个应用实例
				httpGet = new HttpGet(ConfigurationTool.getProperties(Constant.ALIYUN_PROJECTS_URL)+args[0]);
				
			} else { //等于0，说明，用户，没有传入参数，就是查看整个集群的信息
				httpGet = new HttpGet(ConfigurationTool.getProperties(Constant.ALIYUN_PROJECTS_URL));
			}
			 
			CloseableHttpResponse response = httpClient.execute(httpGet);
			
			try {
				
				System.out.println("---------------------------------");
				String bodyAsString = EntityUtils.toString(response.getEntity());
				System.out.println(bodyAsString);
				
				System.out.println("++++++++++++++++下面输出请求头的信息+++++++++++++++++++");
				Header[] allHeaders = response.getAllHeaders();
				
				for(Header header : allHeaders) {
					System.out.println(header.getName() +" ----> "+header.getValue());
				}
				
//				System.out.println("++++++++++++++++输出应用语言信息+++++++++++++++++++");
//				
//				Locale locale = response.getLocale();
//				
//				System.out.println(locale.toString());
//				
//				System.out.println("----------请求头-----------");
//				Header requestHeader = response.getEntity().getContentType();
//				System.out.println(requestHeader.getName()+" ----> "+requestHeader.getValue());
//				
//				HeaderElement[] elements = requestHeader.getElements();
//				System.out.println("============输出请求头的基本信息=============");
//				for(HeaderElement ele: elements) {
//					
//					System.out.println(ele.getName() + " =====>> "+ ele.getValue());
//					
//					NameValuePair[] parameters = ele.getParameters();
//					for(NameValuePair nvp : parameters) {
//						System.out.println(nvp.getName()+" ----> "+nvp.getValue());
//					}
//					
//				}
//				
//				System.out.println("------是不是分块------");
//				System.out.println(response.getEntity().isChunked());
//				
//				System.out.println("------是不是可重复的------");
//				System.out.println(response.getEntity().isRepeatable());
//				
//				System.out.println("------是不是流式的------");
//				System.out.println(response.getEntity().isStreaming());
				
				
				
				
				
				
				
//				System.out.println("----------输出响应体内容----------");
//				System.out.println(response.getEntity().getContent());
				
				
				
				
				
			} catch (Exception e) {
				e.printStackTrace();
			} finally{
				response.close();
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			httpClient.close();
		}
	 }
}
		 
		 
		 
		 
		 
		 
		 
		 
		 
		 
		 
		 
